home *** CD-ROM | disk | FTP | other *** search
/ Champak 29 / Volume 29 - JOGO DISK .iso / Games / jungle_adventure.swf / scripts / __Packages / CallStack.as < prev    next >
Text File  |  2006-11-29  |  4KB  |  166 lines

  1. class CallStack extends Array
  2. {
  3.    static var runningStacks = [];
  4.    static var STOP_STACK = 1.7976931348623157e+308;
  5.    var className = "CallStack";
  6.    var updateInterval = 0;
  7.    var paused = false;
  8.    var running = false;
  9.    var index = 0;
  10.    function CallStack()
  11.    {
  12.       super();
  13.    }
  14.    static function pauseAll()
  15.    {
  16.       var _loc1_ = CallStack.runningStacks.length;
  17.       while((_loc1_ = _loc1_ - 1) > -1)
  18.       {
  19.          CallStack.runningStacks[_loc1_].pause();
  20.       }
  21.       return false;
  22.    }
  23.    static function unpauseAll()
  24.    {
  25.       var _loc1_ = CallStack.runningStacks.length;
  26.       while((_loc1_ = _loc1_ - 1) > -1)
  27.       {
  28.          CallStack.runningStacks[_loc1_].unpause();
  29.       }
  30.    }
  31.    static function stopAll()
  32.    {
  33.       var _loc1_ = CallStack.runningStacks.length;
  34.       while((_loc1_ = _loc1_ - 1) > -1)
  35.       {
  36.          CallStack.runningStacks[_loc1_].stop();
  37.       }
  38.       return false;
  39.    }
  40.    static function buildCall(target, method)
  41.    {
  42.       var _loc2_ = arguments.slice(2);
  43.       _loc2_.target = target;
  44.       _loc2_.method = method;
  45.       return _loc2_;
  46.    }
  47.    function call(target, method)
  48.    {
  49.       this.push(CallStack.buildCall.apply(this,arguments));
  50.    }
  51.    function wait(seconds)
  52.    {
  53.       this.call(this,this.startCountDown,seconds);
  54.    }
  55.    function startCountDown(seconds)
  56.    {
  57.       this.lastTime = getTimer() * 0.001;
  58.       this.countdowntime = seconds;
  59.       return this.countdown;
  60.    }
  61.    function countdown()
  62.    {
  63.       this.countdowntime += this.lastTime - (this.lastTime = getTimer() * 0.001);
  64.       return this.countdowntime <= 0;
  65.    }
  66.    function waitUntilEqual(target, property, targetValue)
  67.    {
  68.       this.call(target,this.untilEqual,property,targetValue);
  69.    }
  70.    function untilEqual(property, targetValue)
  71.    {
  72.       return this[property] == targetValue;
  73.    }
  74.    function start()
  75.    {
  76.       if(this.running)
  77.       {
  78.          return undefined;
  79.       }
  80.       this.running = true;
  81.       CallStack.runningStacks.push(this);
  82.       this.index = 0;
  83.       this.intervalID = setInterval(function(o)
  84.       {
  85.          o.update();
  86.       }
  87.       ,this.updateInterval,this);
  88.    }
  89.    function stop()
  90.    {
  91.       clearInterval(this.intervalID);
  92.       var _loc2_ = CallStack.runningStacks.length;
  93.       while((_loc2_ = _loc2_ - 1) > -1)
  94.       {
  95.          if(CallStack.runningStacks[_loc2_] == this)
  96.          {
  97.             CallStack.runningStacks.splice(_loc2_,1);
  98.          }
  99.       }
  100.       this.running = false;
  101.       return false;
  102.    }
  103.    function finish()
  104.    {
  105.       this.onFinish();
  106.       this.stop();
  107.    }
  108.    function pause()
  109.    {
  110.       this.paused = true;
  111.       return false;
  112.    }
  113.    function resume()
  114.    {
  115.       this.lastTime = getTimer() * 0.001;
  116.       this.paused = false;
  117.    }
  118.    function update()
  119.    {
  120.       if(this.paused)
  121.       {
  122.          return false;
  123.       }
  124.       var _loc3_ = this[this.index];
  125.       var _loc2_ = _loc3_.method.apply(_loc3_.target,_loc3_);
  126.       switch(typeof _loc2_)
  127.       {
  128.          case "function":
  129.             _loc3_.method = _loc2_;
  130.             break;
  131.          case "object":
  132.             if(_loc2_.className == "CallStack")
  133.             {
  134.                this.splice(this.index,1,CallStack.buildCall(_loc2_,_loc2_.update));
  135.             }
  136.             else if(_loc2_.length != null)
  137.             {
  138.                this.splice(this.index,1,_loc2_);
  139.             }
  140.             break;
  141.          default:
  142.             if(_loc2_ || _loc2_ == null)
  143.             {
  144.                this.index = _loc0_ = this.index + 1;
  145.                if(_loc0_ > this.length)
  146.                {
  147.                   this.finish();
  148.                   return true;
  149.                }
  150.                break;
  151.             }
  152.             if(_loc2_ == CallStack.STOP_STACK)
  153.             {
  154.                stop();
  155.                break;
  156.             }
  157.             break;
  158.       }
  159.       return false;
  160.    }
  161.    function toString()
  162.    {
  163.       return "Call Stack";
  164.    }
  165. }
  166.